<?php
namespace App\Http\Controllers\Admin;

use App\model\AdminLogsModel;
use App\Model\ConfigModel;
use App\Models\Config;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;

class ConfigController extends Controller{
	//系统参数
	public function index(){
		$type = request()->type;
		$configs = ConfigModel::where('type',$type)->get();

		return view('admin.config.index',compact('configs','type'));
	}

	//编辑参数
	public function update(Request $request){
		DB::beginTransaction();
		try{
			$list = ConfigModel::where('name',request()->name)->first();
			ConfigModel::where('name',request()->name)->update(['value'=>request()->value]);
			$msg = '编辑【'.$list['param'].'】,变更前:'.$list['value'].',变更后:'.request()->value;
			AdminLogsModel::addLog($msg);
			DB::commit();
			return back()->withErrors('success', '保存成功');
		}catch(Exception $e){
			DB::rollBack();
			return back()->withErrors('danger', '参数错误');
		}
	}
}